import configparser
import os

# path=os.path.dirname(os.path.dirname(__file__))+'/config.ini'
# conf=configparser.ConfigParser()
# conf.read(path,encoding='utf-8')
# print(conf.options('mysql'))
# print(conf.get('mysql','host'))
# print(conf.items('mysql'))
# print(conf.sections())




class ReadConfig:
    def __init__(self):
        self.path=os.path.dirname(os.path.dirname(__file__))+'/config.ini'
        self.conf=configparser.ConfigParser()
        self.conf.read(self.path,encoding='utf-8')
    def read_config(self,*args):
        if len(args)==1:
            res = dict(self.conf.items(*args))
            return res
        elif len(args)==2:
            res = self.conf.get(*args)
            return res
        else:
            return '错了'
if __name__ == '__main__':
    rc=ReadConfig()
    rc_data=rc.read_config('mysql')
    rc_data2=rc.read_config('redis','host')
    rc_data3=rc.read_config('redis','host','1')
    print(rc_data)
    print(rc_data2)
    print(rc_data3)